<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.Date"%>
<html>
<head>
    <script type="text/javascript" src="${ctx}/static/agent/floorInfo.js?v=<%=new Date().getTime() %>"></script>
    <script type="text/javascript">
        $.fn.toJSON = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                var name = this.name;
                var value = this.value;
                var paths = this.name.split(".");
                var len = paths.length;
                var obj = o;
                $.each(paths, function (i, e) {
                    if (i == len - 1) {
                        if (obj[e]) {
                            if (!obj[e].push) {
                                obj[e] = [obj[e]];
                            }
                            obj[e].push(value || '');
                        } else {
                            obj[e] = value || '';
                        }
                    } else {
                        if (!obj[e]) {
                            obj[e] = {};
                        }
                    }
                    obj = o[e];
                });
            });
            return o;
        };
        var ctx = "${ctx}";


        // email新增
        function emailInsert(json) {
            layer.open({
                type: 1,
                title: "新增订单",
                skin: "myclass",
                area: ["500px", "500px"],
                content: $("#edit1").html(),
                success: function (layero, index) {
                    var form = layui.form;
                    layero.addClass('layui-form');
                    layero.find('.layui-layer-btn0').attr('lay-filter', 'fromContent').attr('lay-submit', '');//将按钮弄成能提交的
                    $(layero).find('input[name=email]').val(json.email);
                    $(layero).find('input[name=description]').val(json.description);
                    form.on('select(addressFilter)', function(data){
                        selectfloor(layero)
                        form.render();
                    });
                    $(layero).find('select[name=machineType]').html(valMachineType());
                    form.on('select(machineTypeFilter)', function(data){
                        changeSubject(layero);
                        form.render();
                    });
                    form.render();
                },
                btn: ['提交', '关闭'],
                yes:function (index,layero) {
                    var form = layui.form;
                    form.on('submit(fromContent)', function (data) {
                        var jsonData = $(layero).find("form").toJSON();
                        addEmail(jsonData,function () {
                            layer.close(index);
                        });
                    });
                },
                btn2:function (index) {
                    layer.close(index);
                }
            })
        }

        // 给服务时间赋值
        function valExpectTime(expectTime) {
            var htmlStr = "";
            if(expectTime =='上午' || expectTime == '下午'){
                htmlStr+="<option value='上午'>上午</option><option value='下午'>下午</option>";
            }else{
                for(var i=9;i<=17;i+=0.5){
                    var time;
                    if((i+'').endWith('.5')){
                        time  = (i-0.5)+':30  -  '+(i+0.5)+':00';
                    }else{
                        time = i+':00  -  '+i+':30';
                    }
                    htmlStr +="<option value='"+time+"'>"+time+"</option>";
                }
            }
            return htmlStr;
        }

        function addEmail(json,callback) {
            $.ajax({
                url:ctx+'/repaireInfo/add',
                type : 'POST',
                data:json,
                success:function () {
                    if(callback !=null){
                        callback();
                    }

                }
            });
        }

        function changeSubject(layero) {
            var _machineType = $(layero).find('select[name=machineType]').val();
            $.each(repaireSubject,function (name,value) {
                if(_machineType == value.value){
                    var htmlStr = "";
                    $.each(value.list,function(index,text){
                        htmlStr += "<option value='"+text.id+"'>"+text.words+"</option>";
                    });
                    $(layero).find("select[name=repaireSubject]").empty();
                    $(layero).find("select[name=repaireSubject]").html(htmlStr);
                    return false;
                }
            })
        }

        String.prototype.endWith=function(str){
            if(str==null||str==""||this.length==0||str.length>this.length)
                return false;
            if(this.substring(this.length-str.length)==str)
                return true;
            else
                return false;
            return true;
        }

        //  选择楼层
        function selectfloor(layero) {
            var _address = $(layero).find('select[name=address]').val();
            var $floor = $(layero).find("select[name=floor]");
            $floor.empty();
            var floors= floor_json[_address];
            if(floors == undefined) floors = "";
            var floor_html = "";
            $.each(floors,function (i,v) {
                floor_html +="<option value='"+v+"'>"+v+"</option>";
            });
            $floor.html(floor_html);
        }

        // 给分类赋值
        function valMachineType() {
            var htmlStr = "<option value=''>请选择...</option>";
            $.each(repaireSubject,function (name,value) {
                htmlStr += "<option value = '"+value.value+"'>"+value.text+"</option>";
            });
            return htmlStr;
        }
        $(function () {
            $.getJSON(ctx + '/picWord/listAll', function (result) {
                if (result.code == '0') {
                    repaireSubject = result.data;
                }
            });
        });
    </script>
</head>

<div class="layui-row" id="edit1" style="display: none;">
    <form id = "edit_form" class="layui-form layui-form-pane" action="">
        <input type="hidden" name="source" value="2"/>
        <div class="layui-form-item">
            <label class="layui-form-label">报修人邮箱</label>
            <div class="layui-input-inline">
                <input  id="email"  name="email" layui-autocomplete lay-verify="required" placeholder="请输入"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选项</label>
            <div class="layui-input-inline">
                <select name="machineType" lay-filter="machineTypeFilter">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">判定常用</label>
            <div class="layui-input-inline">
                <select name="repaireSubject">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">报修地点</label>
            <div class="layui-input-inline">
                <select name="address" lay-filter="addressFilter">
                    <option value="">---请选择---</option>
                    <option value="01">兆丰</option>
                    <option value="02">科汇</option>
                    <option value="03">百丽</option>
                    <option value="05">杨浦</option>
                    <option value="04">其他</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">楼层</label>
            <div class="layui-input-inline">
                <select name="floor">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">报修问题</label>
            <div class="layui-input-inline">
                <input  id = "description" name="description"  placeholder="请输入"  class="layui-input">
            </div>
        </div>
    </form>
</div>
<body>

    <div class="layui-row" id="process_00" style="display: none;">
        <form id = "circulation_form" class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">来电号码</label>
                    <div class="layui-input-inline">
                        <label class="layui-form-label" id="editcreateMobile"></label>
                    </div>
                    <img src="" name="pic" alt="" style="display:none; width:150px;position:absolute;right:20px;top:20px;">
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">报修人</label>
                    <div class="layui-input-inline">
                        <label class="layui-form-label" id="editcreatorName"></label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">部门</label>
                    <div class="layui-input-inline">
                        <label class="layui-form-label" id="editcallerDeptName"></label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地点</label>
                    <div class="layui-input-inline">
                        <label class="layui-form-label" id="editaddress"></label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">选项</label>
                    <div class="layui-input-inline">
                        <label class="layui-form-label" id="editmachineType"></label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">判定常用</label>
                    <div class="layui-input-inline">
                        <label class="layui-form-label" id="editrepaireSubject"></label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline">
                        <div class="layui-form-label" id="editdescription"></div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</body>
</html>
